package com.lxl.controller.department;

import com.lxl.mapper.DepartmentMapper;
import com.lxl.pojo.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.apache.ibatis.annotations.Param;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @Date 2021/11/25 17:25
 * @Created by LXLDEMO
 */
@RestController
@RequestMapping("/test")
public class DepartmentController {
    @Autowired
    DepartmentMapper departmentMapper;

    @GetMapping("/getAll")
    public List<Department> getAll(){
        return departmentMapper.getAll();
    }

    /**
     * 根据id获取
     * @param id
     * @return
     */
    @GetMapping("/getById")
    public Department getDepartmentById(@Param("id") Integer id){
        Map<String,Object> param = new HashMap<>();
        param.put("id","" + id);
        return departmentMapper.getDepartmentById(param);
    }
    /**
     * 根据id获取
     * @param id
     * @return
     */
    @GetMapping("/getById2/{id}")
    public Department getDepartmentById2(@PathVariable("id") Integer id){
        Map<String,Object> param = new HashMap<>();
        param.put("id","" + id);
        return departmentMapper.getDepartmentById(param);
    }
}

